package com.fuda.trade.model
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.sql.Timestamp

@Serializable
sealed class Heartbeat(open val id:String) {

    @Serializable
    data class Server(
        @SerialName("svid") override val id: String,
        val timestampMs: Long,
        val desc: String,
       ) : Heartbeat(id)

    @Serializable
    data class AccessibilityService(
        @SerialName("asid") override val id: String,
        val timestampMs: Long,
        val desc: String,
       ) : Heartbeat(id)

    companion object {
        private val json = Json { encodeDefaults = true }

        fun serialize(command: Heartbeat): String {
            return json.encodeToString(command)
        }

        fun deserialize(json: String): Heartbeat {
            return Companion.json.decodeFromString(json)
        }
    }
}
